import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
const router =  new Router({
    mode: 'history',
    routes: [
        {
            path: '/test',
            component: () => import('@/pages/test'),
            meta: {
                title: '测试'
            }
        },
        {
            path: '*',
            component: () => import('@/pages/404.vue'),
            meta: {
                title: '404'
            }
        },
        {
            path: '',
            component: () => import('@/pages/main'),
            meta: {
                title: '首页'
            },
            children:[
                {
                    path: '/Classification',
                    component: () => import('@/pages/Classification'),
                    meta: {
                        title: '分类'
                    }
                },
                {
                    path: '/ShoppingCart',
                    component: () => import('@/pages/ShoppingCart'),
                    meta: {
                        title: '购物车'
                    }
                },
                {
                    path: '/My',
                    component: () => import('@/pages/My'),
                    meta: {
                        title: '我的'
                    }
                }
            ]
        }
    ]

})
router.beforeEach((to, from, next) => {
    if (to.meta) {
        document.title = to.meta.title || ''
    }   
    next() 
})
export default router